import { extend } from 'umi-request';
import requestErrorHandler from '@/Utils/requestErrorHandler';
import { get } from 'local-storage';

const request = extend({
  prefix: '/api',
  timeout: 1000,
  errorHandler: requestErrorHandler,
});

// @ts-ignore
request.interceptors.request.use(async (url, options) => {
  const headers = {
    Authorization: `Bearer ${get('userToken')}`,
  };
  return {
    url,
    options: {
      ...options,
      headers: {
        ...options.headers,
        ...headers,
      },
    },
  };
});

export default request;
